<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/11/5 0005
  Time: 上午 11:24
  To change this template use File | Settings | File Templates.
--%>
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/x-admin/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/x-admin/css/xadmin.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/x-admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/x-admin/js/xadmin.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/x-admin/js/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/x-admin/js/common.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">文件管理</a>
                <a href="">文件设置</a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 180px;"><span class="x-red">*</span>文件存放根目录:</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <input type="text" id="rootPath" name="rootPath" lay-verify="rootPath" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 180px;"><span class="x-red">*</span>同步服务端url:</label>
                <div class="layui-input-inline" style="width: 300px;">
                    <input type="text" id="syncUrl" name="syncUrl" lay-verify="syncUrl" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 180px;"><span class="x-red">*</span>是否正在同步:</label>
                <div class="layui-input-inline" style="width: 80px;">
                    <select id="isRunning" name="isRunning">
                        <option value=0>否</option>
                        <option value=1>是</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 180px;"><span class="x-red">*</span>是否开启同步:</label>
                <div class="layui-input-inline" style="width: 80px;">
                    <select id="isOpen" name="isOpen">
                        <option value=0>否</option>
                        <option value=1>是</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 180px;"><span class="x-red">*</span>同步线层数:</label>
                <div class="layui-input-inline" style="width: 300px;">
                    <input type="text" id="threadNum" name="threadNum" lay-verify="threadNum" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 180px;"><span class="x-red">*</span>每次同步文件的数量:</label>
                <div class="layui-input-inline" style="width: 300px;">
                    <input type="text" id="preSyncNum" name="preSyncNum" lay-verify="preSyncNum" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <a class="layui-btn" id="save" lay-submit="">保存</a>
            </div>
        </form>
    </div>
</div>
<script>

  function renderForm() {
    layui.use('form', function () {
      var form = layui.form(); //高版本建议把括号去掉，有的低版本，需要加()
      form.render();
    });
  }

  $(document).ready(function () {
    initData();
    $("#save").bind("click", function () {
      var rootPath = $("#rootPath").val();
      var syncUrl = $("#syncUrl").val();
      var isRunning = $("select[name='isRunning'] option:selected").val();
      var isOpen = $("select[name='isOpen'] option:selected").val();
      var threadNum = $("#threadNum").val();
      var preSyncNum = $("#preSyncNum").val();
      if (typeof (rootPath) == "undefined" || rootPath == '' || rootPath == null) {
        layer.alert("文件存放根目录不能为空!");
        return false;
      }
      if (typeof (syncUrl) == "undefined" || syncUrl == '' || syncUrl == null) {
        layer.alert("同步服务端url不能为空!");
        return false;
      }
      if (typeof (isRunning) == "undefined" || isRunning == '' || isRunning == null) {
        layer.alert("同步运行状态不能为空!");
        return false;
      }
      if (typeof (isOpen) == "undefined" || isOpen == '' || isOpen == null) {
        layer.alert("同步开启状态不能为空!");
        return false;
      }
      if (typeof (threadNum) == "undefined" || threadNum == '' || threadNum == null) {
        layer.alert("同步线层数不能为空!");
        return false;
      }
      if (typeof (preSyncNum) == "undefined" || preSyncNum == '' || preSyncNum == null) {
        layer.alert("每次同步数量不能为空!");
        return false;
      }
      var data = {
        "rootPath": rootPath,
        "syncUrl": syncUrl,
        "isRunning": isRunning,
        "isOpen": isOpen,
        "threadNum": threadNum,
        "preSyncNum": preSyncNum
      };
      var requestResult = ajaxRequest('${pageContext.request.contextPath}/upload/file/syncConfigSet', data, 'post');
      var result = eval("(" + requestResult + ")");
      if (null != result && null != result.success && result.success) {
        layer.alert(result.message);
        initData();
        return false;
      } else {
        layer.alert(result.message);
        return false;
      }
    });
  });

  /**
   * 初始化数据
   */
  function initData() {
    var requestResult = ajaxRequest('${pageContext.request.contextPath}/upload/file/syncConfigList', {}, 'post');
    var result = eval("(" + requestResult + ")");
    if (null != result && null != result.success && result.success) {
      var data = result.data;
      if (null != data && data.length > 0) {
        var theData = data[0];
        $("#rootPath").val(theData.rootPath);
        $("#syncUrl").val(theData.syncUrl);
        $("#isRunning").val(theData.isRunning);
        $("#isOpen").val(theData.isOpen);
        $("#threadNum").val(theData.threadNum);
        $("#preSyncNum").val(theData.preSyncNum);
      }
    }
    renderForm();
  }
</script>
</body>
</html>
